package kr.co.skplanet.commute.service;

import java.util.List;

import kr.co.skplanet.commute.dao.PostDAO;
import kr.co.skplanet.commute.dao.ReplyDAO;
import kr.co.skplanet.commute.domain.Post;
import kr.co.skplanet.commute.domain.Reply;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service(value="postService")
@Transactional 
public class PostService {
	@Autowired
	PostDAO postDAO;
	
	@Autowired
	ReplyDAO replyDAO;
	
	@Transactional(readOnly = true)
	public List<Post> getPostList() {
		List<Post> list = postDAO.getAll();
		return list;
	}
	
	@Transactional
	public Post savePost(Post post) {
		postDAO.save(post);	// 영속적 객체. 입력되고 ID값이 할당이 된다.
		return post;
	}
	
	@Transactional
	public void saveReply(long postId, Reply reply) {
		Post post = postDAO.select(postId);
		post.addReply(reply);
	}
}	// PostService
